<template>
  <el-dialog title="新增" :visible.sync="dialogVisible" width="30%" class="popup" :before-close="handleClose">
    <el-form ref="ruleForm" :model="addForm" status-icon :rules="rules" label-width="110px" class="demo-ruleForm">
      <el-form-item label="人员姓名" prop="name">
        <el-input v-model="addForm.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="人员类型" prop="type">
        <el-select v-model="addForm.type" autocomplete="off">
          <el-option v-for="item in type" :key="item.type" :label="item.type" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="移入原因" prop="reason">
        <el-input v-model.number="addForm.reason" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" size="small" @click="dialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      addForm: {
        name: '',
        type: '',
        reason: ''
      },
      // 人员类型
      type: [
        {
          type: '访客',
          value: '访客'
        },
        {
          type: '内部人员',
          value: '内部人员'
        },
        {
          type: '可疑人员',
          value: '可疑人员'
        },
        {
          type: '其他人员',
          value: '其他人员'
        }
      ]
    }
  },
  computed: {
    rules() {
      return {
        name: [
          { required: true, message: '请输入人员姓名', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择人员类型', trigger: 'blur' }
        ],
        reason: [
          { required: true, message: '请输入移入原因', trigger: 'blur' }
        ]
      }
    }

  },
  methods: {
    toggleAdd(flag) {
      this.dialogVisible = flag
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => { })
    }
  }
}
</script>

<style lang="scss" scoped>
.popup {
  ::v-deep .el-dialog {
    border-radius: 4px;
  }
  ::v-deep .el-dialog__header {
    border-bottom: 1px solid #cdd0db;
  }
  ::v-deep .el-dialog__body {
    padding: 30px;
  }
}
</style>
